package net.tngou.crawler.company;

import net.tngou.crawler.pojo.Latlng;

public class Distance {

	public static String getDistance(Latlng start,Latlng end){
	    double lat1 = (Math.PI/180)*start.getLat();
	    double lat2 = (Math.PI/180)*end.getLat();

	    double lon1 = (Math.PI/180)*start.getLng();
	    double lon2 = (Math.PI/180)*end.getLng();

	    //地球半径
	    double R = 6371;

	    //两点间距离 km，如果想要米的话，结果*1000
	    double d =  Math.acos(Math.sin(lat1)*Math.sin(lat2)+Math.cos(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1))*R;
	    if(d<1)
	        return (int)d*1000+"m";
	    else
	        return String.format("%.2f",d)+"km";
	}

}
